package org.study.tdengine.mybatisplus.boot.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.pagination.DialectFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * MyBatis-Plus集成分页插件
 *
 * @author doveylovey
 * @version v1.0.0
 * @email 1135782208@qq.com
 * @date 2023年05月13日
 */
@Configuration
@EnableTransactionManagement
@MapperScan(basePackages = {"org.study.tdengine.mybatisplus.boot.mapper"})
public class MyBatisPlusConfig {
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        // 自动分页插件
        PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor();
        // PaginationInnerInterceptor pageInterceptor = new PaginationInnerInterceptor(DbType.TDENGINE);
        // 溢出总页数后是否进行处理，默认 false
        pageInterceptor.setOverflow(false);
        // 单页分页条数限制，默认无限制
        pageInterceptor.setMaxLimit(10000L);
        // 数据库类型，根据类型获取应使用的分页方言
        pageInterceptor.setDbType(DbType.TDENGINE);
        pageInterceptor.setDialect(DialectFactory.getDialect(DbType.TDENGINE));
        interceptor.addInnerInterceptor(pageInterceptor);
        return interceptor;
    }
}
